// const spawn1 = Game.spawns["Spawn1"]
export default function () {
    _.assign(Spawn.prototype, spawnExtension)
}
const spawnExtension = {
    /**
     * creep生成队列
     */
    work: function () {
        console.log("开始工作")
        // 自己已经在生成了 / 内存里没有生成队列 / 生产队列为空 就啥都不干
        if (this.spawning || !this.memory.spawnList || this.memory.spawnList.length === 0) return
        // 进行生成
        const spawnSuccess = this.mainSpawn(this.memory.spawnList[0])
        // 生成成功后移除任务
        if (spawnSuccess) this.memory.spawnList.shift()
    },

    /**
     * 任务加入队列
     * @param taskName 任务名
     * @returns {string}
     */
    addTask: function (taskName) {
        console.log(`${taskName}已加入队列`)
        this.memory.spawnList.push(taskName)
        return this.memory.spawnList.length
    },
    /**
     * 核心生成语句
     * @param taskName{string} 任务名
     * @returns {boolean}
     */
    mainSpawn: function (taskName) {
        const date = new Date()
        const name = `xiaolong${date.getHours()}${date.getMinutes()}${date.getSeconds()}`
        const code = this.spawnCreep(["work", "carry", "move"], `${name}-${taskName}`, {memory: {role: taskName}})
        if (code === 0) {
            return true
        }
    }
}
